<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<title>51微贷</title>
		<link rel="stylesheet" type="text/css" href="../css/reset.css">
		<link rel="stylesheet" type="text/css" href="../css/common.css">
		<link rel="stylesheet" type="text/css" href="../css/icomoon/style.css">
		<script type="text/javascript" src="../js/rem.js"></script>
	</head>

	<body>
		<div class="m-common m-securitypwd">
			<h3 class="header f-pr">
				<span>修改登录密码</span>
				<i class="icon-angle-left f-pa"></i>
			</h3>
			<ul class="mt">
				<li>
					<label>旧密码</label>
					<input type="text" class="oldpwd" placeholder="原登录密码">
					<i class="close-icon f-pa"></i>
				</li>
			</ul>
			<ul class="mt">
				<li>
					<label>新密码</label>
					<input type="password" class="password" placeholder="含字母和数字的6-16位字符">
					<i class="close-icon f-pa"></i>
				</li>
				<li>
					<label>确认密码</label>
					<input type="password" class="confirmpwd" placeholder="再次输入新密码">
					<i class="close-icon f-pa"></i>
				</li>
			</ul>
			<div class="btn-box">
				<a class="btn">确定</a>
			</div>
		</div>
		<script type="text/javascript" src="../js/md5.min.js"></script>
		<script type="text/javascript" src="../js/zepto.min.js"></script>
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>

		<script type="text/javascript">
			mui.plusReady(function() {
				function validate() {
					var oldpwd = $('.oldpwd').val(),
						password = $('.password').val(),
						confirmpwd = $('.confirmpwd').val();
					if(oldpwd == '') {
						mui.toast('请输入原登录密码');
						return false;
					}
					if(password == '') {
						mui.toast('请输入新密码');
						return false;
					}
					if(confirmpwd == '') {
						mui.toast('请再次输入新密码');
						return false;
					}
					if(password != confirmpwd) {
						mui.toast('两次输入的密码不一致');
						return false;
					}
					return true;
				}

				$('.btn').on('tap', function() {
					if(!validate()) {
						return false;
					}
					mui.ajax(base + 'account/modifypassword', {
						type: 'post',
						data: {
							'id': parseInt(plus.storage.getItem('user_id')),
							'old_password': $('.oldpwd').val(),
							'password': $('.password').val(),
							'confirm': $('.confirmpwd').val()
						},
						dataType: 'json',
						headers: sign(md5),
						success: function(data) {
							console.log('修改登录密码：' + JSON.stringify(data));
							if(data.result) {
								mui.toast('密码修改成功');
								setTimeout(function() {
									mui.back();
								}, 1500);
							} else {
								mui.toast(data.message);
							}
						},
						error: function(XMLHttpRequest, textStatus, error) {
							console.error('修改登录错误信息：' + XMLHttpRequest.status);
						}
					});
				});

				$('.icon-angle-left').on('tap', function() {
					mui.back();
				});
			});
		</script>
	</body>

</html>